<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Url;
use think\Session; 


/**
 * 
 */
class Base extends Controller
{
	
	protected function _initialize() 
	{
		if (!Session::has('manage_id')) {
            $this->redirect('index/login/index');
        }else{
        	 $uid = Session::get('manage_id');
        	 $user = db::name('user')->field('id,username,truename,mobile,group_id,folder_id')->find($uid);
        	 /*获取菜单*/
        	 $menu = DB::name('sys_menu')->query('select * from mx_sys_menu where  pid = 0 and is_del = 0 and find_in_set('.$user['group_id'].',type) order by orderid asc');
        	 foreach ($menu as $k => $v) {
        	 	$menu[$k]['child'] = DB::name('sys_menu')->query('select * from mx_sys_menu where  pid = '.$v['id'].' and find_in_set('.$user['group_id'].',type) order by orderid asc');
        	 }
             $customer = $this->customer();
             if($user['folder_id']>0)
             {
                $this->assign('folder',$user['folder_id']);
             }
        	 $this->assign('menu',$menu);
			 $this->assign('user', $user);
        }
	}

    /*修改客户的状态： 7天没有维护的客户自动掉到公海中   备注：只修改意向是  有意向和意向较大的客户  */
    private function  customer()
    {
        $time = time();
        $atime = time()-3600*24*7;
        $sql = "update mx_cust_yixiang set is_public = 1,status = 0 where yixiang in ('B','C') and is_del = 0 and last_time < ".$atime;
        $res = DB::name('cust_yixiang')->query($sql);
        //var_dump(DB::name('cust_yixiang')->getLastSql()).die();
        return $res;
    }
}
?>